﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApp1
{
    public partial class DataShow : Form
    {
        public DataShow()
        {
            InitializeComponent();
        }

        private void DataShow_Load(object sender, EventArgs e)
        {

            chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Size = 10;//x坐标显示的个数-----控制这个数量的大小进行缩放     
            chart1.ChartAreas[0].AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;//设置x轴间隔值单位：秒
            chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//设置X轴的值的间隔大小
            chart1.ChartAreas[0].AxisX.LabelStyle.IsEndLabelVisible = false;//是否在轴末尾显示标记
            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss.ff";//设置X轴的数据样式
            chart1.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Seconds;
            chart1.ChartAreas[0].AxisX.ScaleView.SizeType = DateTimeIntervalType.Seconds; //度量单位
            chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 1;
            chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Seconds;
            chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Seconds;
            chart1.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;//将X轴始终展示
            chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;//将Y轴始终展示
            chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;//设置X轴网格线颜色
            chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;//设置Y轴网格线颜色
            chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;//关闭系统的滚动条，也可以不关闭，就可以滑动
            chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = true;//关闭系统的滚动条，也可以不关闭，就可以滑动
            chart1.Series[0].BorderWidth = 3;//线宽


            //chart1.Series[1].BorderWidth = 2;//线宽
            //chart1.Series[2].BorderWidth = 2;//线宽
            //chart1.Series[3].BorderWidth = 2;//线宽

        }

        private void BT_Start_Click(object sender, EventArgs e)
        {
            timer1.Enabled = !timer1.Enabled;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Random random = new Random();
            chart1.Series[0].Points.AddXY(DateTime.Now, random.Next(50, 110));

            //chart1.Series[1].Points.AddXY(DateTime.Now, TB_TargetValue.Text);
            //chart1.Series[2].Points.AddXY(DateTime.Now, TB_UpperLimitValue.Text);
            //chart1.Series[3].Points.AddXY(DateTime.Now, TB_LowerLimitValue.Text);
            if (chart1.ChartAreas[0].AxisX.ScaleView.Size > 0)
            {
                // 功能, 使X轴的显示范围在最后一刻
                chart1.ChartAreas[0].AxisX.ScaleView.Scroll(System.Windows.Forms.DataVisualization.Charting.ScrollType.Last);
            }
        }



    }
    
}
